package com.kylin.common.weixin.miniapp;

import com.alibaba.fastjson2.JSONObject;
import com.kylin.common.weixin.miniapp.domain.RefundParams;
import com.kylin.common.weixin.miniapp.domain.UnifiedOrderParams;
import com.kylin.common.weixin.util.WxRequest;

/**
 * 支付相关服务
 * @author wuhao
 * @version 1.0 - 2023/4/10
 */
public class PayService {

    private static String UNIFIED_ORDER_URL = "/_/pay/unifiedorder";
    private static String QUERY_ORDER_URL = "/_/pay/queryorder";
    private static String CLOSE_ORDER_URL = "http://api.weixin.qq.com/_/pay/closeorder";
    private static String REFUND_URL = "/_/pay/refund";
    private static String QUERY_REFUND_URL = "http://api.weixin.qq.com/_/pay/queryrefund";
    private static String PAY_CALLBACK_PATH = "/pay/order/callback";
    private static String REFUND_CALLBACK_PATH = "/pay/refund/callback";

    /**
     *  统一下单接口
     * @param orderParams 统一下单接口参数
     * @return
     * @author wuhao
     * @version 1.0.0 - 2023/4/10
     */
    public static JSONObject unifiedOrder(UnifiedOrderParams orderParams){
        return WxRequest.post(UNIFIED_ORDER_URL,orderParams.toJson().toJSONString());
    }

    /**
     * 查询订单接口
     * @param sub_mch_id 子商户ID
     * @param out_trade_no 商户订单号
     * @return
     * @author wuhao
     * @version 1.0.0 - 2023/4/15
     */
    public static JSONObject queryOrder(String sub_mch_id , String out_trade_no) {
        JSONObject params = new JSONObject();
        params.put("sub_mch_id", sub_mch_id);
        params.put("out_trade_no", out_trade_no);

        return WxRequest.post(QUERY_ORDER_URL, params.toJSONString());
    }

    /**
     * 申请退款
     * @param refundParams 退款接口参数
     * @return
     * @author wuhao
     * @version 1.0.0 - 2023/4/10
     */
    public static JSONObject refund(RefundParams refundParams){
        return WxRequest.post(REFUND_URL,refundParams.toJson().toJSONString());
    }


}
